package com.example.factory.api.controller;

import com.example.factory.api.dto.DtoEquipment;
import com.example.factory.api.dto.Response;
import com.example.factory.api.dto.form.DtoEquipmentForm;
import com.example.factory.api.dto.form.DtoQueryEquipmentListForm;
import com.example.factory.api.facade.EquipmentFacade;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Lei Tao
 */
@RestController
@RequestMapping("/admin/equipment")
public class EquipmentController {
    private final EquipmentFacade equipmentFacade;

    public EquipmentController(EquipmentFacade equipmentFacade) {
        this.equipmentFacade = equipmentFacade;
    }

    @PostMapping("/list")
    public Response<List<DtoEquipment>> list(@RequestBody DtoQueryEquipmentListForm dtoQueryEquipmentListForm) {
        return equipmentFacade.retrieveEquipments(dtoQueryEquipmentListForm);
    }

    @GetMapping("/{equipmentGuid}/retrieve")
    public Response<DtoEquipment> retrieve(@PathVariable("equipmentGuid") String guid) {
        return equipmentFacade.retrieveEquipment(guid);
    }

    @GetMapping("/{equipmentGuid}/delete")
    public Response<Void> delete(@PathVariable("equipmentGuid") String guid) {
        return equipmentFacade.deleteEquipment(guid);
    }

    @PostMapping("/save")
    public Response<DtoEquipment> saveOrUpdate(@RequestBody DtoEquipmentForm dtoEquipmentForm) {
        return equipmentFacade.saveOrUpdate(dtoEquipmentForm);
    }

}
